home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************/
- /* PrintWindowProc */
- /************************************************************************************/
-
- #include "MyHeaders.h"
-
- short PrintWindowProc(short Which)
- {
- short PrintWindRetCode = 0;
- TEHandle myPrTEH;
- short outHeight, outLines, outVert, outScroll;
- long outPageNo;
-
- Rect IRect;
- Handle IHandle;
-
- Rect dlogRect;
- short rectHeight, rectWidth;
- short newH, newV;
-
- TPrStatus prStatus; /* status for spooled print */
- short tempResRefNum;
-
-
- switch (windTbl[Which].windRec.refCon) /* Get calling procedure info from */
- { /* the window table */
-
- case (ProcText): /* text window procedure */
- GetPort(&workGrafPtr); /* save GrafPort ptr */
-
- CursorSelect(NIL, NIL, watchCursor); /* set the cursor */
-
- /* get "Printing" dialog */
- myDlogPtr = GetNewDialog (141, NIL, (WindowPtr) -1);
- dlogRect = (*myDlogPtr).portRect; /* position on d/t */
- rectHeight = dlogRect.bottom - dlogRect.top;
- rectWidth = dlogRect.right - dlogRect.left;
- newH = (screenBits.bounds.right - rectWidth) * .50; /* centered horiz. */
- if (newH < 10) /* not less than 10 */
- newH = 10;
- newV = ((screenBits.bounds.bottom - 30 /* vert position */
- - rectHeight)* (.33)) + 30; /* one-third down */
- if (newV < 30) /* not less than 30 */
- newV = 30;
- MoveWindow (myDlogPtr, newH, newV, TRUE); /* move to position */
- ShowWindow (myDlogPtr); /* make visible */
-
- (**prRecHdl).prJob.pIdleProc= (ProcPtr) myIdleProc; /* install idleproc */
-
- prPortPtr = PrOpenDoc(prRecHdl,NIL,NIL); /* open the document */
- firstPage = TRUE;
-
- destRect = (**prRecHdl).prInfo.rPage; /* printed page size */
- destRect.top += 42; /* lower top for icon */
- InsetRect (&destRect, 30,30); /* dest rect is smaller */
-
- /* compute page scroll amount */
- /* and recompute rect sizes. */
- /* destRect a multiple of lineHeight */
- outHeight = (**windTbl[Which].windTEH[0]).lineHeight;
- outVert = destRect.bottom - destRect.top;
- outScroll = (outVert / outHeight ) * outHeight;
- destRect.bottom = destRect.top + outScroll;
-
- viewRect = destRect; /* viewRect coincides */
-
- myPrTEH = TENew(&destRect,&viewRect); /* get TE area for output */
-
- /* copy font info to output */
- (**myPrTEH).txFont = (**windTbl[Which].windTEH[0]).txFont;
- (**myPrTEH).txFace = (**windTbl[Which].windTEH[0]).txFace;
- (**myPrTEH).txSize = (**windTbl[Which].windTEH[0]).txSize;
-
- /* point to text */
- (**myPrTEH).hText = (**windTbl[Which].windTEH[0]).hText;
-
- TECalText(myPrTEH); /* reset line begins */
-
- outPageNo = 0; /* initialize page no */
- outLines = (**myPrTEH).nLines; /* initial # of lines */
- while ((outLines > 0) && (PrError() == 0))
- {
- PrOpenPage (prPortPtr, NIL); /* open the page */
-
- if (!firstPage) /* scroll past prev text */
- {
- if (outLines < (outScroll/outHeight)) /* adjust if < 1 page */
- (**myPrTEH).viewRect.bottom =
- (**myPrTEH).viewRect.top + (outLines * outHeight);
-
- TEScroll(0, -outScroll, myPrTEH); /* scroll the text */
- }
-
- /****************************************/
- /* Draw the icon, or do any other */
- /* graphic or text drawing you want. */
- /****************************************/
- SetRect (&IRect, 0,0, 32,32); /* draw the icon */
- tempResRefNum = CurResFile();
- UseResFile (myResRefNum);
- IHandle = GetResource ('ICN#', 128);
- PlotIcon (&IRect, IHandle);
- UseResFile(tempResRefNum);
-
-
- TEUpdate(&viewRect, myPrTEH); /* draw the text */
-
- outLines -= outScroll/outHeight; /* new # of lines left */
- firstPage = FALSE;
-
- PrClosePage (prPortPtr); /* close the page */
- }
-
- PrCloseDoc(prPortPtr); /* close the document */
-
- SetPort(workGrafPtr); /* restore graf ptr */
-
- if (((**prRecHdl).prJob.bJDocLoop==bSpoolLoop) /* if batch */
- && (PrError() == 0))
- {
- UseResFile (initResRefNum); /* for H/P printer */
- PrPicFile (prRecHdl,NIL,NIL,NIL,&prStatus); /* print the spool */
- }
-
- DisposDialog(myDlogPtr); /* get rid of dlog box */
- break;
- }
-
- return PrintWindRetCode;
- }